"插件区
if empty(glob('~/.config/nvim/autoload/plug.vim'))
  silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync
endif
"curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    "让插件正常工作的一些设置
        set nocompatible
        filetype on
        filetype indent on
        filetype plugin on
        filetype plugin indent on

    "插件的声明区
    call plug#begin('~/.vim/plugged')
        "appearance
        Plug 'https://gitee.com/karl1864/vim-airline_vim-airline'
        Plug 'https://gitee.com/karl1864/dracula_vim'
        Plug 'https://github.com/RRethy/vim-illuminate'
        Plug 'https://github.com/tpope/vim-surround'
        Plug 'https://github.com/gcmt/wildfire.vim'
        Plug 'https://github.com/lfv89/vim-interestingwords'
        " Plug 'https://github.com/connorholyday/vim-snazzy'
        " Plug 'https://github.com/Rigellute/rigel'
        " Plug 'https://github.com/lmintmate/blue-mood-vim'

        "nerdtree
        Plug 'https://github.com/scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
        "nerdtree-git-plugin
        Plug 'https://github.com/Xuyuanp/nerdtree-git-plugin'
        "ranger
        Plug 'https://github.com/rbgrouleff/bclose.vim'
        Plug 'https://github.com/francoiscabrol/ranger.vim'
        "lazygit
        Plug 'https://github.com/kdheepak/lazygit.nvim', { 'branch': 'nvim-v0.4.3' }
        "undotree
        Plug 'https://github.com/mbbill/undotree'
        "bookmark
        Plug 'https://github.com/kshenoy/vim-signature'
        "startify
        Plug 'https://github.com/mhinz/vim-startify'
        "comment
        Plug 'https://github.com/scrooloose/nerdcommenter'
        "ack!
        Plug 'https://github.com/mileszs/ack.vim'
        "clipboard
        Plug 'https://github.com/junegunn/vim-peekaboo'
        "fzf
        Plug 'https://github.com/junegunn/fzf.vim'
        "clever-f
        Plug 'https://github.com/rhysd/clever-f.vim'
        "gn grammer
        Plug 'https://github.com/kalcutter/vim-gn'
        "bp grammer
        Plug 'https://github.com/psyill/blueprint-vim-syntax'
        "gyp grammer
        Plug 'https://github.com/kelan/gyp.vim'
        "selinux grammer
        Plug 'https://github.com/lzap/vim-selinux'
        "smali grammer
        Plug 'https://github.com/mylesx86-64/vim-smali'
        "qmake grammar
        Plug 'https://github.com/matveyt/vim-qmake'

        if exists("g:my_module_coc") && g:my_module_coc == 1
            "coc
            Plug 'https://gitee.com/karl1864/coc.nvim_from_github', {'branch': 'release'}
        endif

        if exists("g:my_module_go") && g:my_module_go == 1
            "go
            Plug 'https://github.com/fatih/vim-go', { 'do': ':GoUpdateBinaries' }
        endif

        if exists("g:my_module_web") && g:my_module_web == 1
            "html, css
            Plug 'https://github.com/mattn/emmet-vim'
            Plug 'https://github.com/JulesWang/css.vim'
            " Plug 'https://github.com/cakebaker/scss-syntax.vim'
            "vim highlight
            Plug 'https://github.com/posva/vim-vue'
            Plug 'https://github.com/digitaltoad/vim-pug'
            "javascript
            Plug 'https://github.com/pangloss/vim-javascript'
            "vim-hexokinase
            Plug 'https://github.com/RRethy/vim-hexokinase', { 'do': 'make hexokinase' }
        endif

        if exists("g:my_module_markdown") && g:my_module_markdown == 1
            "markdown
            Plug 'https://github.com/godlygeek/tabular'
            Plug 'https://github.com/plasticboy/vim-markdown'
            Plug 'https://github.com/dhruvasagar/vim-table-mode'
            if has ("nvim")
                Plug 'https://github.com/iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } }
            endif
            if exists("g:my_module_wiki") && g:my_module_wiki == 1
                "wiki
                Plug 'https://github.com/vimwiki/vimwiki'
            endif
            " "rst2html (deprecated)
            "Plug 'https://github.com/gu-fan/riv.vim'
        endif

        if exists("g:my_module_translator") && g:my_module_translator == 1
            "translate
            Plug 'https://github.com/voldikss/vim-translator'
        endif

        if exists("g:my_module_tagbar") && g:my_module_tagbar == 1
            "taglist
            "Plug 'https://github.com/vim-scripts/taglist.vim'
            Plug 'https://github.com/majutsushi/tagbar'
        endif

        if exists("g:my_module_pdf") && g:my_module_pdf == 1
            "pdf
            Plug 'https://github.com/makerj/vim-pdf'
        endif

        if exists("g:my_module_doc") && g:my_module_doc == 1
            "chinese vim doc
            Plug 'https://github.com/yianwillis/vimcdoc'
        endif
    call plug#end()

    "vim-airline
        let g:airline#extensions#coc#enabled = 1
        let g:airline#extensions#branch#enabled = 1
        let g:airline#extensions#tabline#enabled = 1
        let g:airline#extensions#tabline#show_buffers = 1
        let g:airline#extensions#tabline#formatter = 'unique_tail'
        let g:airline#extensions#tabline#tab_nr_type = 1
        let g:airline#extensions#tabline#show_tab_nr = 1
        let g:airline#extensions#tabline#fnametruncate = 16
        let g:airline#extensions#tabline#fnamecollapse = 2
        let g:airline#extensions#tabline#buffer_idx_mode = 1
        let g:airline#extensions#tabline#buffer_nr_show = 0
        let g:airline_powerline_fonts = 0
        let g:airline_left_sep = ''
        let g:airline_right_sep = ''

    "vim-colorscheme
        if has ("nvim")
            set termguicolors
        endif

        "colorscheme snazzy
        "colorscheme rigel
        colorscheme dracula
            "启用定位光标的行列，设置行列样式
            set cursorline
            set cursorcolumn
            if has ("nvim")
                highlight CursorLine ctermfg=None ctermbg=236 guifg=None guibg=#111111
                highlight CursorColumn ctermfg=None ctermbg=236 guifg=None guibg=#222222
            else
                highlight CursorLine ctermbg=236 guibg=#111111
                highlight CursorColumn ctermbg=236 guibg=#222222
            endif
        "colorscheme blue-mood
        highlight Normal guibg=NONE ctermbg=None
        highlight comment ctermfg=DarkGreen guifg=#008800

    "wildfire.vim
        map  <enter>    <plug>(wildfire-fuel)
        vmap <c-enter>  <plug>(wildfire-water)
        let g:wildfire_objects = [
                    \ "iw", "iW",
                    \ "i'", "a'",
                    \ "i\"", "a\"",
                    \ "i)", "a)",
                    \ "i]", "a]",
                    \ "i}", "a}",
                    \]

    "vim-interestingwords
        nnoremap <silent> <leader>[ :call InterestingWords('n')<cr>
        vnoremap <silent> <leader>[ :call InterestingWords('v')<cr>
        nnoremap <silent> <leader>] :call UncolorWord('<c-r>=expand("<cword>")<cr>')<cr>
        vnoremap <silent> <leader>] :call UncolorAllWords()<cr>

        nnoremap <silent> n :call WordNavigation(1)<cr>
        nnoremap <silent> N :call WordNavigation(0)<cr>
        let g:interestingWordsTermColors = ['154', '121', '211', '137', '214', '222']
        let g:interestingWordsGUIColors = ['#8CCBEA', '#A4E57E', '#FFDB72', '#FF7272', '#FFB3FF', '#9999FF']
        let g:interestingWordsRandomiseColors = 1

    "nerdtree
        map st            :NERDTreeToggle<cr>

    "nerdtree-git-plugin
        let g:NERDTreeIndicatorMapCustom = {
            \ "Modified" : "✹",
            \ "Staged"   : "✚",
            \ "Untracked": "✭",
            \ "Renamed"  : "➜",
            \ "Unmerged" : "═",
            \ "Deleted"  : "✖",
            \ "Dirty"    : "✗",
            \ "Clean"    : "✔︎",
            \ "Unknown"  : "?"
        \ }

    "ranger

    "lazygit
        let g:lazygit_floating_window_winblend = 0 " transparency of floating window
        let g:lazygit_floating_window_scaling_factor = 0.9 " scaling factor for floating window
        let g:lazygit_floating_window_corner_chars = ['╭', '╮', '╰', '╯'] " customize lazygit popup window corner characters
        let g:lazygit_use_neovim_remote = 0 " fallback to 0 if neovim-remote is not installed
        nmap <silent> sh :LazyGit<cr>

    "undotree
        map su            :UndotreeToggle<cr>

    "vim-signature
        let g:SignatureMap = {
            \ 'Leader'             :  "m",
            \ 'PlaceNextMark'      :  "m,",
            \ 'DeleteMark'         :  "sd",
            \ 'GotoNextSpotAlpha'  :  "m<LEADER>",
            \ 'GotoNextSpotByPos'  :  "mn",
            \ 'GotoPrevSpotByPos'  :  "mp",
            \ 'ListLocalMarks'     :  "m/",
            \ }

    "nerdcommenter
        let g:NERDSpaceDelims = 1
        let g:NERDCompactSexyComs = 1
        let g:NERDDefaultAlign = 'left'
        let g:NERDAltDelims_java = 1
        let g:NERDCommentEmptyLines = 1
        let g:NERDTrimTrailingWhitespace = 1
        let g:NERDToggleCheckAllLines = 1

    "ack!
        nnoremap sa :Ack<cr>

    "fzf
        let g:fzf_preview_window = ['right:50%', 'ctrl-/']
        nnoremap <silent> <leader>o :Ag<cr>
        nnoremap <silent> <leader>e :Ag <C-R>=expand("<cword>")<cr><cr>
        nnoremap <silent> <leader>q :Files<cr>

    "clever-f
        map ; <Plug>(clever-f-repeat-forward)
        map , <Plug>(clever-f-repeat-back)

    if exists("g:my_module_coc") && g:my_module_coc == 1
        "coc
            set nobackup
            set nowritebackup
            set updatetime=300
            set signcolumn=yes
            inoremap <silent><expr> <TAB>
                  \ coc#pum#visible() ? coc#pum#next(1) :
                  \ CheckBackspace() ? "\<Tab>" :
                  \ coc#refresh()
            inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

            inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
                                          \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

            function! CheckBackspace() abort
              let col = col('.') - 1
              return !col || getline('.')[col - 1]  =~# '\s'
            endfunction

            nmap <silent> [g <Plug>(coc-diagnostic-prev)
            nmap <silent> ]g <Plug>(coc-diagnostic-next)
            nmap <silent> gd <Plug>(coc-definition)
            nmap <silent> gy <Plug>(coc-type-definition)
            nmap <silent> gi <Plug>(coc-implementation)
            nmap <silent> gr <Plug>(coc-references)
            nnoremap <silent> K :call ShowDocumentation()<CR>

            function! ShowDocumentation()
              if CocAction('hasProvider', 'hover')
                call CocActionAsync('doHover')
              else
                call feedkeys('K', 'in')
              endif
            endfunction

            autocmd CursorHold * silent call CocActionAsync('highlight')
            nmap <leader>rn <Plug>(coc-rename)

            augroup mygroup
              autocmd!
              " Setup formatexpr specified filetype(s).
              autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
              " Update signature help on jump placeholder.
              autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
            augroup end

            " Applying codeAction to the selected region.
            " Example: `<leader>aap` for current paragraph
            xmap <leader>a  <Plug>(coc-codeaction-selected)
            nmap <leader>a  <Plug>(coc-codeaction-selected)
            nmap <leader>ac  <Plug>(coc-codeaction)
            nmap <leader>qf  <Plug>(coc-fix-current)
            nmap <leader>cl  <Plug>(coc-codelens-action)

            " Remap <C-f> and <C-b> for scroll float windows/popups.
            if has('nvim-0.4.0') || has('patch-8.2.0750')
              nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
              nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
              inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
              inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
              vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
              vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
            endif

            " Add `:Format` command to format current buffer.
            command! -nargs=0 Format :call CocActionAsync('format')

            " Add `:Fold` command to fold current buffer.
            command! -nargs=? Fold :call     CocAction('fold', <f-args>)

            " Add `:OR` command for organize imports of the current buffer.
            command! -nargs=0 OR   :call     CocActionAsync('runCommand', 'editor.action.organizeImport')

            " Add (Neo)Vim's native statusline support.
            " NOTE: Please see `:h coc-status` for integrations with external plugins that
            " provide custom statusline: lightline.vim, vim-airline.
            set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

            "" Mappings for CoCList
            "" Show all diagnostics.
            "nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
            "nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
            "nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
            "" Find symbol of current document.
            "nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
            "" Search workspace symbols.
            "nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
            "" Do default action for next item.
            "nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
            "" Do default action for previous item.
            "nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
            "" Resume latest coc list.
            "nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>

            " coc-marketplace: CocList marketplace
            let g:coc_global_extensions = [
                        \ 'coc-clang-format-style-options',
                        \ 'coc-git',
                        \ 'coc-json',
                        \ 'coc-lists',
                        \ 'coc-marketplace',
                        \ 'coc-pairs',
                        \ 'coc-pyright',
                        \ 'coc-snippets',
                        \ 'coc-vimlsp',
                        \ 'coc-yank',
                        \]
            if exists("g:my_module_web") && g:my_module_web == 1
                let g:coc_global_extensions += ['coc-html', 'coc-css', 'coc-scssmodules']
            endif
            if exists("g:my_module_java") && g:my_module_java == 1
                let g:coc_global_extensions += ['coc-java']
            endif
            "'coc-tsserver', 'coc-go', 'coc-python', 'coc-java', \ 'coc-sh',

            imap <c-j> <plug>(coc-snippets-expand)
            let g:coc_snippet_next = '<c-j>'
            let g:coc_snippet_prev = '<c-k>'

            nnoremap <silent> <leader>p  :<c-u>CocList -A --normal yank<cr>

            let g:coc_disable_startup_warning = 1

        "coc-pairs
            autocmd FileType markdown let b:coc_pairs_disabled = ['`']

        "coc-go
            let g:go_version_warning = 0

        "coc-git
        "]gg: next change
        "[gg: prev change
        "]gc: next conflict
        "[gc: prev conflict
        "sgs: show chunk diff
        "?g: in/around git-chunk
        "gb: git blame
            nmap ]gg <Plug>(coc-git-nextchunk)
            nmap [gg <Plug>(coc-git-prevchunk)
            nmap ]gc <Plug>(coc-git-nextconflict)
            nmap [gc <Plug>(coc-git-prevconflict)
            nmap sgs <Plug>(coc-git-chunkinfo)
            omap ig <Plug>(coc-git-chunk-inner)
            xmap ig <Plug>(coc-git-chunk-inner)
            omap ag <Plug>(coc-git-chunk-outer)
            xmap ag <Plug>(coc-git-chunk-outer)
            nnoremap gb :echo b:coc_git_blame<cr>
    endif

    if exists("g:my_module_go") && g:my_module_go == 1
        "vim-go
            autocmd filetype go nnoremap <buffer> ga :GoInfo<cr>
            autocmd filetype go nmap     <buffer> <C-RightMouse> <C-t>
            "
            let g:go_template_autocreate                 = 0
            let g:go_textobj_enabled                     = 0
            let g:go_auto_type_info                      = 0
            "
            let g:go_highlight_array_whitespace_error    = 1
            let g:go_highlight_build_constraints         = 1
            let g:go_highlight_chan_whitespace_error     = 1
            let g:go_highlight_extra_types               = 1
            let g:go_highlight_fields                    = 1
            let g:go_highlight_format_strings            = 1
            let g:go_highlight_function_calls            = 1
            let g:go_highlight_function_parameters       = 1
            let g:go_highlight_functions                 = 1
            let g:go_highlight_generate_tags             = 1
            let g:go_highlight_methods                   = 1
            let g:go_highlight_operators                 = 1
            let g:go_highlight_space_tab_error           = 1
            let g:go_highlight_string_spellcheck         = 1
            let g:go_highlight_structs                   = 1
            let g:go_highlight_trailing_whitespace_error = 1
            let g:go_highlight_types                     = 1
            let g:go_highlight_variable_assignments      = 0
            let g:go_highlight_variable_declarations     = 0
            "
            let g:go_highlight_diagnostic_errors         = 0
            let g:go_highlight_diagnostic_warnings       = 0
    endif

    if exists("g:my_module_web") && g:my_module_web == 1
        "emmet-vim
            let g:user_emmet_mode='inv'
            let g:user_emmet_install_global = 0
            autocmd filetype html,css,scss.css EmmetInstall
            au BufRead,BufNewFile *.scss set filetype=scss.css
            autocmd FileType scss set iskeyword+=-

        "vim-vue
            let g:vue_pre_processors = ['pug']

        "vim-hexokinase
            let g:Hexokinase_highlighters = ['virtual']
            let g:Hexokinase_ftEnabled = ['css', 'html', 'javascript']
    endif

    if exists("g:my_module_markdown") && g:my_module_markdown == 1
        "vim-markdown
            let g:vim_markdown_folding_disabled = 1

        "markdown-preview.nvim
            nmap <leader>m    :MarkdownPreview<cr>
            nmap <leader>mt    :TableFormat<cr>
            "
            let g:mkdp_auto_start = 0
            let g:mkdp_auto_close = 0
            let g:mkdp_refresh_slow = 1
            let g:mkdp_command_for_global = 1
            let g:mkdp_open_to_the_world = 1
            let g:mkdp_open_ip = 'localhost'
            let g:mkdp_browser = 'chromium'
            let g:mkdp_echo_preview_url = 1
            let g:mkdp_browserfunc = ''
            let g:mkdp_markdown_css = expand('~/my/src/markdown/markdown.css')
            let g:mkdp_highlight_css = expand('~/my/src/markdown/highlight.css')
            let g:mkdp_port = '8888'
            let g:mkdp_page_title = '${name}'
            let g:mkdp_preview_options = {
                \ 'mkit': {},
                \ 'katex': {},
                \ 'uml': {},
                \ 'maid': {},
                \ 'disable_sync_scroll': 1,
                \ 'sync_scroll_type': 'middle',
                \ 'hide_yaml_meta': 1,
                \ 'sequence_diagrams': {}
                \ }

        if exists("g:my_module_wiki") && g:my_module_wiki == 1
            "vimwiki
                let g:vimwiki_list = [
                     \{"path": "~/my/link/wiki/",
                     \ "syntax": "markdown",
                     \ "ext": ".md"
                     \}]
        endif

        "riv.vim
            "nmap <silent> <leader>t :Riv2HtmlAndBrowse<cr>
    endif

    if exists("g:my_module_translator") && g:my_module_translator == 1
        "vim-translate-me
            "<leader>w 翻译光标下的文本，在窗口中显示
            nmap <silent> <leader>w <plug>TranslateW
            vmap <silent> <leader>w <plug>TranslateWV
            "<leader>r 替换光标下的文本为翻译内容
            nmap <silent> <leader>r <plug>TranslateR
            vmap <silent> <leader>r <plug>TranslateRV
            "
            let g:vtm_default_to_lang = 'zh'
    endif

    if exists("g:my_module_tagbar") && g:my_module_tagbar == 1
        "tagbar
            nnoremap sg :TagbarToggle<cr>
            "
            let g:tagbar_width = 50
            let g:tarbar_autoclose = 1
            let g:tarbar_autofocus = 0
            let g:tarbar_sort = 0
            let g:tarbar_indent = 1
            let g:tarbar_foldlevel = 1
            let g:tarbar_autoshowtag = 0
            let g:tarbar_autopreview = 0
    endif
